from rest_framework import serializers

from apps.goods.models import SKU
from apps.orders.models import *


class OrderSKUSerializer(serializers.ModelSerializer):

    class Meta:
        model = SKU
        fields = ("default_image", "name")


class OrderGoodsSerializer(serializers.ModelSerializer):
    sku = OrderSKUSerializer()

    class Meta:
        model = OrderGoods
        fields = ("sku", "price", "count")


class OrderInfoSerializer(serializers.ModelSerializer):
    # 一对多的关系 看 model 与 skus(外键的related_name)关系
    skus = OrderGoodsSerializer(many=True)

    class Meta:
        model = OrderInfo
        fields = "__all__"

